<template>
  <div class="app-container">
    <el-form ref="majorForm" :model="majorData" label-width="120px">
      <!-- <el-form-item label="专业ID">
        <el-input v-model="majorData.id" placeholder="请输入专业ID" :disabled="isEdit"></el-input>
      </el-form-item> -->
      <el-form-item label="专业名称">
        <el-input
          v-model="majorData.majorName"
          placeholder="请输入专业名称"
        ></el-input>
      </el-form-item>
      <!-- <el-form-item label="创建时间">
        <el-date-picker
          v-model="majorData.create_time"
          type="datetime"
          placeholder="选择创建时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          :disabled="isEdit"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="修改时间">
        <el-date-picker
          v-model="majorData.update_time"
          type="datetime"
          placeholder="选择修改时间"
          value-format="yyyy-MM-dd HH:mm:ss"
          :disabled="isEdit"
        ></el-date-picker>
      </el-form-item> -->
      <!-- <el-form-item label="状态">
        <el-select v-model="majorData.status" placeholder="请选择状态" :disabled="isEdit">
          <el-option label="激活" value="active"></el-option>
          <el-option label="非激活" value="inactive"></el-option>
          <el-option label="已删除" value="deleted"></el-option>
        </el-select>
      </el-form-item> -->
      <el-form-item>
        <el-button type="primary" @click="submitForm">提交</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { insertMajor } from "@/api/major";
export default {
  props: {
    isEdit: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      majorData: {
        majorName: "",
        // status: 'active'
      },
    };
  },
  methods: {
    submitForm() {
      this.$refs.majorForm.validate((valid) => {
        if (valid) {
          // 在这里处理表单提交逻辑，例如发送请求到后端API
          console.log("提交的专业数据:", this.majorData);
          // 以下代码示例，实际应用中需要替换为API调用
          // this.saveMajor(this.majorData);
          insertMajor(this.majorData).then((res) => {
            if (res.code == 200) {
              this.$message({
                message: "新增成功",
                type: "success",
              });
            } else {
              this.$message({
                message: res.msg ,
                type: "error",
              });
            }
            console.log(res);

            this.majorData.majorName = "";
          });
        } else {
          
          console.log("表单验证失败");
          return false;
        }
      });
    },
    resetForm() {
      this.$refs.majorForm.resetFields();
    },
  },
};
</script>

